<template>
  <el-table :data="get_userList" border style="width: 100%">
    <el-table-column prop="uid" label="用户编号" > </el-table-column>
    <el-table-column prop="username" label="用户名称"> </el-table-column>
    <el-table-column prop="rolename" label="所属角色"> </el-table-column>
    <el-table-column prop="status" label="状态">
      <template v-slot='item'>
        <el-button type="primary" size='small' plain v-if="item.row.status == 1">启用</el-button>  
        <el-button type="danger" size='small' plain v-else>禁用</el-button>  
      </template>
    </el-table-column>
    <el-table-column prop="address" label="操作"> 
        <template v-slot='item'>
        <el-button type="primary" size='small' @click="editItem">编辑</el-button>
        <el-button type="danger" size='small' @click="del(item.row.uid)">删除</el-button>
        </template>
    </el-table-column>
  </el-table>
</template>
  
  <script>
  import {mapGetters,mapActions} from "vuex"
  import {userdelete} from "@/request/api.js"
export default {
  data() {
    return {
    
    };
  },
  methods:{
    ...mapActions({
      action_userList:"user/action_userList"
    }),
    //1.点击编辑按钮，显示编辑弹框
    editItem(){
        //通知父组件，显示弹框
        this.$emit("edit")
    },
    //点击删除按钮
    del(uid){
      //a.询问是否真的删除
      this.$confirm('此操作将永久删除该项, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          //删除 -- 发起请求，删除数据库中的数据
          let res = await userdelete({uid});
          if(res.code == 200){
            this.$message.success(res.msg);
            //更新页面，重新获取最新的数据的数据
            this.action_userList();
          }else{
            this.$message.warning(res.msg)
          }
        }).catch(() => {
          this.$message.info("已取消删除"); 
        });
    }
  },
  computed:{
    ...mapGetters({
      get_userList:"user/get_userList"
    })
  },
  mounted(){
    this.action_userList();
  }
};
</script>